﻿using B.S.BaseData.Api.Write.Applicantion.Command;
using B.S.BaseData.ErrorCode;
using B.S.BataBase.Domain;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;

namespace B.S.BaseData.Api.Write.Controllers
{
    /// <summary>
    /// 基础数据 -API -写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PermissionController : ControllerBase
    {
        private readonly IMediator mediator;

        public PermissionController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 权限添加接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> CreatePermission(CreatePermissionCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 权限编辑接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<APIResult<int>> UpdatePermission(UpdatePermissionCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 权限删除接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<APIResult<int>> Handle(DelPermissionCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 权限显示接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<PermissionsModel>>> GetPermission([FromQuery]GetPermissionCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 角色新增
        /// </summary>
        /// <param name="command">实体</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> RoleAdd(RoleAddCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 角色修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> RoleUpdate(RoleUpdateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<APIResult<int>> RoleDelete(RoleDeleteCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 用户新增
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> UserAdd(UserAddCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 用户修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]

        public async Task<APIResult<int>> UserUpdate(UserUpdateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 用户删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> UserDelete(UserDeleteCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 修改角色状态
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> RoleStateUpdate(RoleStateUpdateCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 修改用户状态
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> UserStateUpdate(UserStateUpdateCommand command)
        {
            return await mediator.Send(command);
        }
    }
}
